package io.jsen.meta.diff.support;

import com.google.common.reflect.TypeToken;
import lombok.Getter;
import lombok.Setter;

/**
 * @author jsen
 * @date 2021/4/12
 */
@SuppressWarnings("UnstableApiUsage")
public class MetaDiffModel<T> {
    private final TypeToken<T> typeToken;
    @Getter
    @Setter
    private T newNativeObj;
    @Getter
    @Setter
    private T oldNativeObj;

    public MetaDiffModel(TypeToken<T> typeToken, T newNativeObj, T oldNativeObj) {
        this.typeToken = typeToken;
        this.newNativeObj = newNativeObj;
        this.oldNativeObj = oldNativeObj;
        if (newNativeObj != null && oldNativeObj != null &&
                !newNativeObj.getClass().equals(oldNativeObj.getClass())) {
            throw new IllegalArgumentException("diff对象类型必须一致");
        }
    }

    public TypeToken<T> getToken() {
        return typeToken;
    }
}
